﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FaultBackService.Models;

namespace FaultBackService.BLL
{
    class RealTimeFaultDataDaily
    {
        DAL.RealTimeFaultDataDaily dal = new DAL.RealTimeFaultDataDaily();

        IDictionary<int, Models.RealTimeFault> _dictFault;
        IDictionary<int, Models.Turbine> _dictTurbine;

        public RealTimeFaultDataDaily()
        {
            _dictFault = new RealTimeFault().GetDict();
            _dictTurbine = new Turbine().GetDict();
        }
        /// <summary>
        /// 获取表RealTimeFaultDataDaily中的最新日期，没有返回默认值(1970-1-1)
        /// </summary>
        /// <returns></returns>
        internal DateTime GetLastDate()
        {
            return dal.GetLastDate();
        }

        /// <summary>
        /// 创建模型对象
        /// </summary>
        internal Models.RealTimeFaultDataDaily Create(int faultId, int turbineId, DateTime date, float total_FaultLevel1, float total_FaultLevel2, float total_FaultLevel3)
        {
            var total = total_FaultLevel1 + total_FaultLevel2 + total_FaultLevel3;
            var fault = _dictFault[faultId];
            Models.RealTimeFaultDataDaily model = new Models.RealTimeFaultDataDaily() {
                FaultId=faultId,
                FaultDescription= fault.FaultDescription,
                TurbineId=turbineId,
                TurbineName=_dictTurbine[turbineId].TurbineName,
                ComponentId= fault.ComponentId,
                ComponentName=fault.ComponentName,
                SensorId=fault.SensorId,
                SensorZH=fault.SensorZH,
                SensorEN=fault.SensorEN,
                Date=date,
                TotalTime=total,
                TotalTime_Level1=total_FaultLevel1,
                TotalTime_Level2=total_FaultLevel2,
                TotalTime_Level3=total_FaultLevel3
            };
            return model;
        }

        /// <summary>
        /// 写入数据库，返回写入的记录数目
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        internal int AddList(IList<Models.RealTimeFaultDataDaily> list)
        {
            return dal.AddList(list);
        }
    }
}
